/**
 * @file demo3.c
 * @author WRS (1352509846@qq.com)
 * @brief 无重复字符的最长字符串
 * 给定一个字符串s，请你找出其中不含重复字符的最长子串的长度
 * @version 0.1
 * @date 2021-09-09
 * 
 * @copyright Copyright (c) 2021
 * 
 */

#include <stdio.h>
#include <math.h>
#include <string.h>
int lengthOfLongestSubstring(char * s)
{
    int len = strlen(s);
    if(len == 0) return 0;

    int S[256] = {0};
    int i,j,m=0;

    for(i=0,j=0;j<len;j++)
    {
        S[s[j]]++;
        while(S[s[j]]>1)
        {
            S[s[i]]--;
            i++;
        }
        m = fmax(m,j-i+1);
    }
    return m;
}


int main(int argc, char const *argv[])
{
    /* code */
    char s[200] = {0};
    printf("请输入一个字符串：");
    scanf("%s",s);

    printf("无重复最长字符串%d\n",lengthOfLongestSubstring(s));
    return 0;
}

